<?php


namespace App\Services;


use Psr\Log\LoggerInterface;
use Zipkin\Endpoint;
use Zipkin\Reporters\Http;
use Zipkin\Samplers\BinarySampler;
use Zipkin\TracingBuilder;

class TracerFactory
{
    public static function make()
    {
        $servicename = config('w7opentracing.servicename');
        $httpendpoint = config('w7opentracing.zipkin.httpendpoint');
//				$port = config('w7opentracing.report_port');

        $endpoint = Endpoint::create(
            $servicename,
            null,
            null,
            null
        );
        $reporter = new Http(
            ['endpoint_url' => $httpendpoint],
            null,
            app()->make(LoggerInterface::class)
        );
        $sampler = BinarySampler::createAsAlwaysSample();
        $tracing = TracingBuilder::create()
            ->havingLocalEndpoint($endpoint)
            ->havingSampler($sampler)
            ->havingReporter($reporter)
            ->build();

        return new \ZipkinOpenTracing\Tracer($tracing);
    }
}
